#-*- coding: utf8 -*-

from tutor.scripts import *
from tutor.plugins.sympy import *

with display_block('Entradas'):
    x1 = One * oneof(0, 0, 1, 2, 3) * oneof(1, -1)
    x2 = One * oneof(0, 0, 1, 2, 3) * oneof(1, -1)
    y1 = One * oneof(0, 0, 1, 2, 3) * oneof(1, -1)
    y2 = One * oneof(0, 0, 1, 2, 3) * oneof(1, -1)
    x1, x2 = min(x1, x2), max(x1, x2)
    y1, y2 = min(y1, y2), max(y1, y2) 
    sigma0 = symbols('sigma_0', each_char=False)
    upper_t = oneof(True, False)
    P1 = (x1, y1)
    P2 = (x1, y2)
    P3 = (x2, y2)
assert x1 != x2
assert y1 != y2

with display_block('Variáveis auxiliares'):
    reta = y1 + (x - x1) * (y2 - y1) / (x2 - x1)
    reta2 = solve(y - reta, x)[0]

with display_block('Respostas'):
    res = (y**2).integrate([y, reta, y2])
    res = res.integrate([x, x1, x2])
    inercia_x = correta = together(res * sigma0)
    
    res = (x**2).integrate([y, reta, y2])
    res = res.integrate([x, x1, x2])
    inercia_y = together(res * sigma0)
    inercia_z = inercia_x + inercia_y

    res = (y**2).integrate([x, x1, x2])
    res = res.integrate([y, y1, y2])
    quadrado_x = together(res * sigma0)

    res = (x**2).integrate([x, x1, x2])
    res = res.integrate([y, y1, y2])
    quadrado_y = together(res * sigma0)
    quadrado_z = quadrado_x + quadrado_y

    dis_1 = together((quadrado_x + correta)/2)
    dis_2 = together((inercia_x + inercia_y)/2)
    del res